import jsrsasign from 'jsrsasign'
/**
 * 解析token专用
 * @param {*} token 
 */
export const decodeToken = (token) => {
  let obj = null
  if (token !== '') {
    const payload = jsrsasign.KJUR.jws.JWS.parse(token)
    if (payload.hasOwnProperty('payloadObj')) {
      obj = payload.payloadObj
    }
  }
  return obj
}

/**
 * 解析用户名
 * @param {*} token 
 */
export const getUsernameFromToken = (token) => {
  const decoded = decodeToken(token);
  return decoded.claims.userName;
}
/**
 * 解析头像
 */
export const getUserAvatarURLFromToken = (token) => {
  const decoded = decodeToken(token);
  return decoded.claims.avatarURL;
}